package com.gjs.freechat.server.component;

import com.gjs.freechat.server.component.bean.UserInfo;
import com.gjs.freechat.utils.StringSimilartyUtils;

public class UserSimilarity {
	
	public static double ageSimilarity(int age1, int age2) {
		return Math.exp(-(Math.abs(age1 - age2) / 12));
	}
	
	public static double genderSimilarity(int a, int b) {
		return (a == b) || (a == 0 || b == 0) ? 0.65 : 1;
	}
	
	public static double similarityMeasure(UserInfo user1, UserInfo user2) {
		double age = ageSimilarity(user1.getAge(), user2.getAge());
		double gender = genderSimilarity(user1.getGender(), user2.getGender());
		double interest = StringSimilartyUtils.wordsVectorSimilaryMeasure(user1.getInterests(), user2.getInterests());
		double intro = StringSimilartyUtils.textSimilaryMeasure(user1.getIntroduction(), user2.getIntroduction());
		return age + gender + interest + intro;
	}
	
	public static void main(String[] args) {
		UserInfo user1 = new UserInfo();
		user1.setAge(20);
		user1.setGender(1);
		user1.setInterests(null);
		user1.setIntroduction("dwef");
		
		UserInfo user2 = new UserInfo();
		user2.setAge(23);
		user2.setGender(1);
		user2.setInterests(null);
		user2.setIntroduction("我性格很好");
		
		System.out.println(similarityMeasure(user1, user2));
	}
}
